package han.chensing.latos.common.level.content.objects;

import com.badlogic.gdx.graphics.Color;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

import han.chensing.latos.common.file.annotation.CirnoNotSerialize;

public class CommonNote extends CommonObject implements Serializable{
    @Serial
    private static final long serialVersionUID=11451404L;

    public static final Color TAP_COLOR=Color.BLUE;
    public static final Color DRAG_COLOR=Color.YELLOW;
    public static final Color HOLD_COLOR=Color.CYAN;
    public static final Color FLICK_COLOR=Color.PINK;

    protected float distanceHeight;
    protected float distanceToLineCenter;
    protected NoteType noteType;
    protected boolean shown=true;
    protected boolean backGoing=false;
    @CirnoNotSerialize
    protected CommonLine bindCommonLine;
    protected float startTime;
    protected float endTime;

    @CirnoNotSerialize
    protected transient Object[] editorExtraData=new Object[16];

    public enum NoteType{
        Tap,Drag,Flick,Hold,DirectFlick
    }

    public float getDistanceHeight() {
        return distanceHeight;
    }

    public void setDistanceHeight(float distanceHeight) {
        this.distanceHeight = distanceHeight;
    }

    public float getDistanceToLineCenter() {
        return distanceToLineCenter;
    }

    public void setDistanceToLineCenter(float distanceToLineCenter) {
        this.distanceToLineCenter = distanceToLineCenter;
    }

    public NoteType getNoteType() {
        return noteType;
    }

    public void setNoteType(NoteType noteType) {
        this.noteType = noteType;
    }

    public boolean isShown() {
        return shown;
    }

    public void setShown(boolean shown) {
        this.shown = shown;
    }

    public boolean isBackGoing() {
        return backGoing;
    }

    public void setBackGoing(boolean backGoing) {
        this.backGoing = backGoing;
    }

    public CommonLine getBindLine() {
        return bindCommonLine;
    }

    public void setBindLine(CommonLine bindCommonLine) {
        this.bindCommonLine = bindCommonLine;
    }

    public float getStartTime() {
        return startTime;
    }

    public void setStartTime(float startTime) {
        this.startTime = startTime;
    }

    public float getEndTime() {
        return endTime;
    }

    public void setEndTime(float endTime) {
        this.endTime = endTime;
    }

    public Object[] getEditorExtraData() {
        return editorExtraData;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CommonNote commonNote = (CommonNote) o;
        return Float.compare(commonNote.distanceHeight, distanceHeight) == 0 &&
                distanceToLineCenter == commonNote.distanceToLineCenter &&
                shown == commonNote.shown &&
                backGoing == commonNote.backGoing &&
                noteType == commonNote.noteType &&
                Objects.equals(bindCommonLine, commonNote.bindCommonLine) &&
                Objects.equals(startTime, commonNote.startTime) &&
                Objects.equals(endTime,commonNote.endTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(distanceHeight, distanceToLineCenter, noteType, shown, backGoing, bindCommonLine, startTime,endTime);
    }

    public static Color getNoteColor(CommonNote commonNote){
        if (commonNote.getNoteType()==null)
            return Color.BLUE;
        return switch (commonNote.getNoteType()) {
            case Drag -> DRAG_COLOR;
            case Hold -> HOLD_COLOR;
            case Flick -> FLICK_COLOR;
            default -> TAP_COLOR;
        };
    }
}
